package cc.customer.web.seaAdmin;

import cc.customer.common.domain.QueryRequest;
import cc.customer.common.domain.ResponseBo;
import cc.customer.common.utils.Constant;
import cc.customer.common.utils.DateUtil;
import cc.customer.common.utils.FileUtils;
import cc.customer.onschool.domain.OnSchoolResource;
import cc.customer.onschool.services.OnSchoolService;
import cc.customer.system.domain.MyUser;
import cc.customer.web.sys.controller.base.BaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value="/seaOnschool")
public class OnSchoolController extends BaseController {

   private Logger logger = LoggerFactory.getLogger(BaseController.class);

   @Autowired
   private OnSchoolService onSchoolService;


   @RequestMapping(value="/index")
   public String loadIndex(){
      return "customer/seaManage/seaOnSchool/onSchool_index";
   }

   @RequestMapping(value="/loadCustomerDetail")
   public String loadCustomerDetail(){
      return "customer/myCustomer/myCustomerdetail/onSchool_detail";
   }

   @RequestMapping(value="/loadFenpeiDetail")
   public String loadFenpeiDetail(){
      return "customer/seaManage/seaOnSchool/onSchool_fenpeiDetail";
   }

   /**初始化表单*/
   @RequestMapping(value="/list")
   @ResponseBody
   public Map<String, Object> selectAllList(QueryRequest request, OnSchoolResource onSource){
      MyUser user = this.getCurrentUser();
      return super.selectByPageNumSize(request,() -> this.onSchoolService.selectByResource(onSource,user));
   }

   /**客户导出excel**/
   @RequestMapping("/exportOnSchoolData")
   @ResponseBody
   public ResponseBo exportOnSchoolData(String keyids){
      try {
         MyUser user = this.getCurrentUser();
         List<OnSchoolResource> list = onSchoolService.exportOnschoolInfo(keyids,user);
         ResponseBo responseBo = FileUtils.createExcelByPOIKit("网校客户资料表", list, OnSchoolResource.class);
         return responseBo;
      }catch (Exception e){
         logger.error("大资源名单导出大资源客户失败："+e.getMessage());
      }
      return ResponseBo.error("导出失败");
   }

   /**批量更新客户的信息**/
   @RequestMapping(value = "/onschoolFenpei")
   @ResponseBody
   public ResponseBo onschoolFenpei(OnSchoolResource resource,String ids,String names){
      MyUser user = this.getCurrentUser();
      String distributor = user.getUserUuid();
      String username = user.getUsername();
      resource.setOsDistributor(distributor);
      resource.setOsRecent(Constant.GENZONG_RECORD_FENPEI+resource.getOsMyCustomerName());
      resource.setOsRecentTime(DateUtil.getCurrentDate("yyyy-MM-dd HH:mm:ss"));
      return onSchoolService.batchUpdateBykeyId(resource,ids,names,username);
   }

   /**查询客户的详情**/
   @RequestMapping("/viewOnschoolDetail")
   @ResponseBody
   public ResponseBo viewBigEmpDetail(String keyid){
      MyUser user = this.getCurrentUser();

      return onSchoolService.findCustomerDetailByid(keyid,user);
   }
   /**查询网校资源的 客户的标签**/
   @RequestMapping("/selectSeaOnschoolLabel")
   @ResponseBody
   public  ResponseBo selectSeaOnschoolLabel(String keyid){
      return onSchoolService.selectOnshoolLabel(keyid);
   }



   /**修改用户得基本信息**/
   @RequestMapping(value = "/OnschoolEditinfo")
   @ResponseBody
   public ResponseBo bigempEditinfo(OnSchoolResource resource){
      MyUser user = this.getCurrentUser();
      return onSchoolService.updateOnshoolEmpInfoByBpId(resource,user);
   }

}




